<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function runAsync(x) {
            const p = new Promise(resolve => setTimeout(() => resolve(x,console.log(x)),1000));
            return p;
        }

        function runReject(x) {
            const p = new Promise(
                (res,rej) => 
                setTimeout(
                    () => rej(`Error:${x}`,console.log(x),)
                ,1000*x)
            )
            return p;
        }
        // 多个异步任务中，只要有一个失败了，就不会执行 .then
        // all 过程中就算提前失败了，但是所有的promise 实例都有执行机会，但是被丢弃了
        Promise.all([runAsync(1),runReject(4),runAsync(3),runReject(2)])
            .then(res => console.log(res))
            // Promise.all 多个失败，只会输出第一个失败
            .catch(err => console.log(err));
    </script>
</body>
</html>